package com.yanqu.road.server.cmd.activity;

import com.yanqu.road.entity.activity.ActivityUserDigFloor;
import com.yanqu.road.entity.activity.huashigang.HuaShiGangFloorCellData;
import com.yanqu.road.pb.activity.DigFloorActivityProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ActivityDigModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_ACTIVITY_DIG_DATA, desc = "请求沙漠宝库数据")
public class GetDigActivityFloorDataCmd extends AbstractCommand {
    private int activityId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        DigFloorActivityProto.GetDigFloorDataReqMsg req = DigFloorActivityProto.GetDigFloorDataReqMsg.parseFrom(packet.getBytes());
        activityId = req.getActivtyId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        DigFloorActivityProto.GetDigFloorDataRespMsg.Builder resp = DigFloorActivityProto.GetDigFloorDataRespMsg.newBuilder();
        ActivityUserDigFloor floorData = player.getModule(ActivityDigModule.class).getFloorData(activityId);
        if (floorData != null) {
            for (HuaShiGangFloorCellData data : floorData.getCellDataList()) {
                DigFloorActivityProto.DigCellData.Builder msg = DigFloorActivityProto.DigCellData.newBuilder();
                msg.setOpen(data.isOpen());
                if (data.isOpen()) {
                    msg.setReward(data.getReward());
                } else {
                    msg.setReward("");
                }
                resp.addCell(msg);
            }
            resp.setGotBigReward(floorData.getGotBigReward());
            resp.setRet(0);
            resp.setFloor(floorData.getFloor());
        } else {
            resp.setRet(GameErrorCode.E_ACTIVITY_NO_FOUND);
        }
        player.sendPacket(ClientProtocol.U_ACTIVITY_DIG_DATA, resp);

    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
